<template>
  <div v-if="Object.keys(goods).length !== 0" class="goods-info">
    <div class="info-desc clear-fix">
      <div class="start">
      </div>
      <div class="desc">{{goods.desc}}</div>
      <div class="end"></div>
    </div>
    <div class="info-key">{{goods.detailImage[0].key}}</div>
    <div class="info-list">
      <img v-for="(item, index) in goods.detailImage[0].list" :src="item" alt="" :key="index"
      @load='handleLoadImg'>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    goods: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data () {
    return {
      counter: 0,
      imgL: 0
    }
  },
  methods: {
    handleLoadImg () {
      // 每张图片全部加载完 每张都会影响，所以判断所有图片都加载完了就可以进行一次回调就可以了
      this.counter += 1
      // if (this.counter === this.goods.detailImage[0].list.length) { console.log(1) }这种也可以 下面这种性能更好
      if (this.counter === this.imgL) {
        // 告诉外面所有图片加载完成
        this.$emit('imgLoad')
      }
    }
  },
  watch: {
    goods: {
      handler () {
        // 获取图片个数 为了避免多次调用右边这一长串 --直接用监听
        this.imgL = this.goods.detailImage[0].list.length
      },
      deep: true
    }
  }
}
</script>

<style scoped>
  .goods-info {
    padding: 20px 0;
    border-bottom: 5px solid #f2f5f8;
  }

  .info-desc {
    padding: 0 15px;
  }

  .info-desc .start, .info-desc .end {
    width: 90px;
    height: 1px;
    background-color: #a3a3a5;
    position: relative;
  }

  .info-desc .start {
    float: left;
  }

  .info-desc .end {
    float: right;
  }

  .info-desc .start::before, .info-desc .end::after {
    content: '';
    position: absolute;
    width: 5px;
    height: 5px;
    background-color: #333;
    bottom: 0;
  }

  .info-desc .end::after {
    right: 0;
  }

  .info-desc .desc {
    padding: 15px 0;
    font-size: 14px;
  }

  .info-key {
    margin: 10px 0 10px 15px;
    color: #333;
    font-size: 15px;
  }
  .info-list {
    font-size: 0 ;
  }
  .info-list img {
    width: 100%;
  }
</style>
